home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / AMReminder / DReminder.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  4.4 KB  |  276 lines  |  [TEXT/CWIE]

  1. // DReminder.cp -- data container class for AMReminder
  2.  
  3. #include "DReminder.h"
  4.  
  5. #include <LFileStream.h>
  6.  
  7. #include <DateTimeUtils.h>
  8.  
  9. //----------
  10. DReminder::DReminder ()
  11. {
  12.     GetLongDateTime (&mDateTime);
  13.     LString::CopyPStr ("\p", mMessage);
  14.     mShowAlert = false;
  15.     mShowIcon = false;
  16.     mPlaySound = false;
  17.     mSoundIndex = 1;
  18. }
  19.  
  20. //----------
  21. DReminder::~DReminder ()
  22. {
  23. }
  24.  
  25. //----------
  26. void    DReminder::CopyFrom (
  27.     DReminder*        inOther)
  28. {
  29.     mDateTime = inOther->mDateTime;
  30.     LString::CopyPStr (inOther->mMessage, mMessage);
  31.     mShowAlert = inOther->mShowAlert;
  32.     mShowIcon = inOther->mShowIcon;
  33.     mPlaySound = inOther->mPlaySound;
  34.     mSoundIndex = inOther->mSoundIndex;
  35. }
  36.  
  37. //----------
  38. void    DReminder::ReadFromFile (
  39.     LFileStream*    inFile)
  40. {
  41.     inFile->ReadBlock (&mDateTime, sizeof (mDateTime));
  42.     inFile->ReadPString (mMessage);
  43.     inFile->ReadBlock (&mShowAlert, sizeof (mShowAlert));
  44.     inFile->ReadBlock (&mShowIcon, sizeof (mShowIcon));
  45.     inFile->ReadBlock (&mPlaySound, sizeof (mPlaySound));
  46.     inFile->ReadBlock (&mSoundIndex, sizeof (mSoundIndex));
  47. }
  48.  
  49. //----------
  50. void    DReminder::WriteToFile (
  51.     LFileStream*    inFile)
  52. {
  53.     inFile->WriteBlock (&mDateTime, sizeof (mDateTime));
  54.     inFile->WritePString (mMessage);
  55.     inFile->WriteBlock (&mShowAlert, sizeof (mShowAlert));
  56.     inFile->WriteBlock (&mShowIcon, sizeof (mShowIcon));
  57.     inFile->WriteBlock (&mPlaySound, sizeof (mPlaySound));
  58.     inFile->WriteBlock (&mSoundIndex, sizeof (mSoundIndex));
  59. }
  60.  
  61.  
  62. //----------
  63. LongDateRec        DReminder::GetDateTime () const
  64. {
  65.  
  66.     return mDateTime;
  67. }
  68.  
  69. //----------
  70. void    DReminder::SetDateTime (
  71.     LongDateRec        inValue)
  72. {
  73.     mDateTime = inValue;
  74.     
  75.     SignalDataChanged (idDateTime);
  76. }
  77.  
  78.  
  79. //----------
  80. StringPtr    DReminder::GetMessage (
  81.     Str255        outPtr) const
  82. {
  83.  
  84.     if (outPtr != nil) {
  85.         LString::CopyPStr (mMessage, outPtr);
  86.     }
  87.     return (StringPtr)mMessage;
  88. }
  89.  
  90. //----------
  91. void    DReminder::SetMessage (
  92.     ConstStringPtr    inValue)
  93. {
  94.     LString::CopyPStr (inValue, mMessage);
  95.     
  96.     SignalDataChanged (idMessage);
  97. }
  98.  
  99. //----------
  100. void    DReminder::SetMessage (
  101.     CharsHandle        inValue)
  102. {
  103.     SetPStr (mMessage, sizeof (mMessage), inValue);
  104.     
  105.     SignalDataChanged (idMessage);
  106. }
  107.  
  108.  
  109. //----------
  110. Boolean        DReminder::GetShowAlert () const
  111. {
  112.  
  113.     return mShowAlert;
  114. }
  115.  
  116. //----------
  117. void    DReminder::SetShowAlert (
  118.     Boolean        inValue)
  119. {
  120.     mShowAlert = inValue;
  121.     
  122.     SignalDataChanged (idShowAlert);
  123. }
  124.  
  125.  
  126. //----------
  127. Boolean        DReminder::GetShowIcon () const
  128. {
  129.  
  130.     return mShowIcon;
  131. }
  132.  
  133. //----------
  134. void    DReminder::SetShowIcon (
  135.     Boolean        inValue)
  136. {
  137.     mShowIcon = inValue;
  138.     
  139.     SignalDataChanged (idShowIcon);
  140. }
  141.  
  142.  
  143. //----------
  144. Boolean        DReminder::GetPlaySound () const
  145. {
  146.  
  147.     return mPlaySound;
  148. }
  149.  
  150. //----------
  151. void    DReminder::SetPlaySound (
  152.     Boolean        inValue)
  153. {
  154.     mPlaySound = inValue;
  155.     
  156.     SignalDataChanged (idPlaySound);
  157. }
  158.  
  159.  
  160. //----------
  161. SInt16        DReminder::GetSoundIndex () const
  162. {
  163.  
  164.     return mSoundIndex;
  165. }
  166.  
  167. //----------
  168. void    DReminder::SetSoundIndex (
  169.     SInt16        inValue)
  170. {
  171.     mSoundIndex = inValue;
  172.     
  173.     SignalDataChanged (idSoundIndex);
  174. }
  175.  
  176.  
  177. //----------
  178. StringPtr    DReminder::GetDateString (
  179.     Str255        outPtr) const
  180. {
  181.     LongDateTime        longSeconds;
  182.     static Str255        dateString;
  183.  
  184.     LongDateToSeconds (&mDateTime, &longSeconds);
  185.     LongDateString (&longSeconds, shortDate, dateString, nil);
  186.  
  187.     return dateString;
  188.  
  189. }
  190.  
  191. //----------
  192. void    DReminder::SetDateString (
  193.     ConstStringPtr    inValue)
  194. {
  195.  
  196.     SignalDataChanged (idDateString);
  197. }
  198.  
  199. //----------
  200. void    DReminder::SetDateString (
  201.     CharsHandle        inValue)
  202. {
  203.  
  204.     SignalDataChanged (idDateString);
  205. }
  206.  
  207.  
  208. //----------
  209. StringPtr    DReminder::GetTimeString (
  210.     Str255        outPtr) const
  211. {
  212.     LongDateTime        longSeconds;
  213.     static Str255        timeString;
  214.  
  215.     LongDateToSeconds (&mDateTime, &longSeconds);
  216.     LongTimeString (&longSeconds, false, timeString, nil);
  217.  
  218.     return timeString;
  219.  
  220. }
  221.  
  222. //----------
  223. void    DReminder::SetTimeString (
  224.     ConstStringPtr    inValue)
  225. {
  226.  
  227.     SignalDataChanged (idTimeString);
  228. }
  229.  
  230. //----------
  231. void    DReminder::SetTimeString (
  232.     CharsHandle        inValue)
  233. {
  234.  
  235.     SignalDataChanged (idTimeString);
  236. }
  237.  
  238.  
  239. //----------
  240. LongDateRec        DReminder::GetYearMonthDay () const
  241. {
  242.     return mDateTime;
  243.  
  244. }
  245.  
  246. //----------
  247. void    DReminder::SetYearMonthDay (
  248.     LongDateRec        inValue)
  249. {
  250.     mDateTime.ld.year = inValue.ld.year;
  251.     mDateTime.ld.month = inValue.ld.month;
  252.     mDateTime.ld.day = inValue.ld.day;
  253.     SignalDataChanged (idDateTime);
  254.  
  255.     SignalDataChanged (idYearMonthDay);
  256. }
  257.  
  258.  
  259. //----------
  260. LongDateRec        DReminder::GetHourMinute () const
  261. {
  262.     return mDateTime;
  263.  
  264. }
  265.  
  266. //----------
  267. void    DReminder::SetHourMinute (
  268.     LongDateRec        inValue)
  269. {
  270.     mDateTime.ld.hour = inValue.ld.hour;
  271.     mDateTime.ld.minute = inValue.ld.minute;
  272.     SignalDataChanged (idDateTime);
  273.  
  274.     SignalDataChanged (idHourMinute);
  275. }
  276.